import com.hansheng.dao.SheetDao;
import com.hansheng.entity.OutFormEntity;

import java.util.List;

/**
 * Created by GoldenMan on 2017/5/29.
 */
public class testSheetDao extends SpringTestCase {
    private SheetDao sheetDao;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        sheetDao = (SheetDao) getFactory().getBean("sheetDao");
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testMaterialDao() {
        // Created by GoldenMan at 2017/7/8    TODO:获取outFormNoCounter
        String cutMaterialNo = "chuku";
        String hql = "from OutFormEntity o where o.outFormNo LIKE ? order by o.outId desc";
        Object[] params = {cutMaterialNo + "%"};
        List<OutFormEntity> outFormEntityList = sheetDao.getOutFormByQuery(hql, params);
        int counter = Integer.parseInt(outFormEntityList.get(0).getOutFormNo().substring(cutMaterialNo.length())) + 1;
        System.out.println(counter);
        // Created by GoldenMan at 2017/6/3    TODO:获取OutFormList
//        String whereHql="where o.status=?";
//        Object[] params={0};
//        List list=sheetDao.getOutFormListByCondition(whereHql,params);
//        JSONArray returnArray=new JSONArray();
//        for (int i = 0; i < list.size(); i++) {
//            returnArray.add(list.get(i));
//        }
//        System.out.println(returnArray.toString());
        // Created by GoldenMan at 2017/6/3    TODO:添加outForm和outdetails
//        OutFormEntity outFormEntity = new OutFormEntity();
//        outFormEntity.setOutFormNo("测试outFormNo");
//        outFormEntity.setOperator(1);
//        boolean flag = sheetDao.saveOutForm(outFormEntity);
//        System.out.println(outFormEntity.getOutId());
//        String sd = "[{\"addTime\":1494930758000,\"count\":1,\"height\":600,\"length\":600,\"material\":\"材料1\",\"mid\":1,\"msNo\":\"20170522-1\",\"msid\":\"20170522-1\",\"name\":\"操作人员1\",\"oid\":1,\"position\":\"记录员\",\"sid\":2,\"status\":0,\"weightAct\":2999,\"weightThe\":2500,\"width\":600,\"cutMaterialFormNo\":\"11\"},{\"addTime\":1496225924000,\"count\":6,\"height\":6,\"length\":6,\"material\":\"材料1\",\"mid\":1,\"msNo\":\"20170531-1\",\"msid\":\"20170531-1\",\"name\":\"操作人员1\",\"oid\":1,\"position\":\"记录员\",\"sid\":20,\"status\":1,\"weightAct\":6,\"weightThe\":6,\"width\":6,\"cutMaterialFormNo\":\"11\"},{\"addTime\":1496226204000,\"count\":2,\"height\":2,\"length\":2,\"material\":\"材料1\",\"mid\":1,\"msNo\":\"20170531-7\",\"msid\":\"20170531-7\",\"name\":\"操作人员1\",\"oid\":1,\"position\":\"记录员\",\"sid\":26,\"status\":1,\"weightAct\":2,\"weightThe\":2,\"width\":2,\"cutMaterialFormNo\":\"11\"}]";
//        JSONArray sheetDetails = JSONArray.parseArray(sd);
//        for (int i = 0; i < sheetDetails.size(); i++) {
//            JSONObject detail = (JSONObject) sheetDetails.get(i);
//            // Created by GoldenMan at 2017/5/15    TODO:check availble
//            OutDetailEntity outDetailEntity = new OutDetailEntity();
//            outDetailEntity.setOutId(outFormEntity.getOutId());
//            outDetailEntity.setCutMaterialFormNo(detail.get("cutMaterialFormNo").toString());
//            outDetailEntity.setSid(Integer.parseInt(detail.get("sid").toString()));
//            outDetailEntity.setLength(Integer.parseInt(detail.get("length").toString()));
//            outDetailEntity.setWidth(Integer.parseInt(detail.get("width").toString()));
//            outDetailEntity.setCount(Integer.parseInt(detail.get("count").toString()));
//            outDetailEntity.setWeightThe(Double.parseDouble(detail.get("weightThe").toString()));
//            outDetailEntity.setWeightAct(Double.parseDouble(detail.get("weightAct").toString()));
//            outDetailEntity.setStatus(3);
//            flag &= sheetDao.saveOutDetail(outDetailEntity);
//        }
//        if (flag) System.out.println("ok");
//        else System.out.println("not ok");
        // Created by GoldenMan at 2017/6/3    TODO:添加sheet
//        String whereHql = "where o.mid=? and o.length>=? and o.width>=? and o.height>=?";
//        Object[] params = new Object[]{1,100,100,100};
//        List list=sheetDao.getSheetListByCondition(whereHql,params,0,20);
//        JSONArray jsonArray=new JSONArray();
//        for (int i = 0; i < list.size(); i++) {
//            VSheetEntity vSheetEntity=(VSheetEntity) list.get(i);
//            JSONObject tempJSON=new JSONObject();
//            tempJSON.put("sid",vSheetEntity.getSid());
//            tempJSON.put("msid",vSheetEntity.getMsNo());
//            tempJSON.put("length",vSheetEntity.getLength());
//            tempJSON.put("width",vSheetEntity.getWidth());
//            tempJSON.put("height",vSheetEntity.getHeight());
//            tempJSON.put("count",vSheetEntity.getCount());
//            tempJSON.put("weight_the",vSheetEntity.getWeightThe());
//            tempJSON.put("weight_act",vSheetEntity.getWeightAct());
//            tempJSON.put("addTime",vSheetEntity.getAddTime());
//            tempJSON.put("status",vSheetEntity.getStatus());
//            tempJSON.put("name",vSheetEntity.getName());
//            jsonArray.add(tempJSON);
//        }
//        System.out.println(jsonArray.toString());
    }
}